﻿namespace DomainServices.Tools
{
    using System;
    using System.Globalization;
    using System.IO;

    public class CleanRiaClientFilesTask : RiaClientFilesTask
    {
        private void DeletePreviouslyWrittenFiles()
        {
            foreach (string str in base.FilesPreviouslyWritten())
            {
                if (File.Exists(str))
                {
                    base.LogMessage(string.Format(CultureInfo.CurrentCulture, Resource.ClientCodeGen_Deleting_Orphan, new object[] { str }));
                    base.DeleteFileFromVS(str);
                    base.DeleteFolderIfEmpty(Path.GetDirectoryName(str));
                }
            }
        }

        protected override bool ExecuteInternal()
        {
            this.DeletePreviouslyWrittenFiles();
            base.DeleteCodeGenMetafileLists();
            base.DeleteFolderIfEmpty(base.GeneratedCodePath);
            return true;
        }
    }
}

